using System;

namespace SharpMud.Server.App
{
	/// <summary>
	/// The implementation if IAppExecutionHandle
	/// </summary>
	/// <remarks>Made internal for security reasons.</remarks>
	public class AppExecutionHandle : MarshalByRefObject, IAppExecutionHandle
	{
		private SharpMud.Server.App.Application _App;
		internal AppExecutionHandle(SharpMud.Server.App.Application app)
		{
			_App = app;
		}

        public AppExecutionHandle()
            :this(SharpMud.Server.App.Hosting.ApplicationHost.GlobalInstance.App)
        {
        }

		#region IAppExecutionHandle Members

		public void Initialize()
		{
			_App.___Initialize();
		}

		public void Start()
		{
			_App.___Start();
		}

		public void Pause()
		{
			_App.___Pause();
		}

		public void Resume()
		{
			_App.___Resume();
		}

		public void Stop()
		{
			_App.___Stop();
		}

		public void Dispose()
		{
            if (_App == null)
                return;
            else
            {
                _App.Dispose();
                this._App = null;
            }
		}

		public SharpMud.Server.App.AppStatus Status
		{
			get
			{
				return _App.___Status;
			}
		}

		public event AppStatusChangeHandler StatusChanged
		{
			add
			{
				_App.___StatusChanged += value;
			}
			remove
			{
				_App.___StatusChanged -= value;
			}
		}
		#endregion
	}
}
